package campus.service.impl;

import campus.mapper.CredentialsLogMapper;
import campus.model.Account;
import campus.model.CredentialsLog;
import campus.service.AccountBookService;
import campus.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：wang
 * @description：TODO
 * @date ：2020/5/10 14:43
 */
@Service
public class AccountBookServiceImpl implements AccountBookService{
    @Autowired
    private CredentialsLogMapper credentialsLogMapper;
    @Override
    public PageResult findByAllPageSize(CredentialsLog credentialsLog, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CredentialsLog> findlog = (Page<CredentialsLog>) credentialsLogMapper.findByAllPageSize(credentialsLog);
        List<CredentialsLog> list = findlog.getResult();
        for (CredentialsLog c: list) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            c.setDatea(simpleDateFormat.format(c.getJzDate()));
            c.setJzProof(c.getJzProof()+"-"+c.getJzH());
            c.setFx("借");
            if (c.getJzJfprice().length()>0){
                c.setYe(c.getJzJfprice());
            }
            else{
                c.setYe("-"+c.getJzDfprice());
            }
        }
        return new PageResult(findlog.getTotal(),findlog.getResult());
    }

    @Override
    public List selectAllkm() {
        return credentialsLogMapper.selectAllkm();
    }


    @Override
    public Map selectAllzz(CredentialsLog credentialsLog, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CredentialsLog> findlog = (Page<CredentialsLog>) credentialsLogMapper.selectAllzz();
        List<CredentialsLog> list = findlog.getResult();
        int a=0,b=0;
        for (CredentialsLog c: list) {
            if (c.getJzJfprice()!=null){
                a+=Integer.parseInt(c.getJzJfprice());
            }
            if (c.getJzDfprice()!=null){
                b+=Integer.parseInt(c.getJzDfprice());
            }
        }
        HashMap<Object,Object> map = new HashMap<>();
        map.put("a",a);
        map.put("b",b);
        map.put("p",new PageResult(findlog.getTotal(),findlog.getResult()));
        return map;
    }
    @Override
    public Map selectAllkmye(CredentialsLog credentialsLog, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<CredentialsLog> findlog = (Page<CredentialsLog>) credentialsLogMapper.selectAllkmye();
        List<CredentialsLog> list = findlog.getResult();
        int a=0,b=0,d=0,e=0;
        for (CredentialsLog c: list) {
            if (c.getJzJfprice()!=null){
                a+=Integer.parseInt(c.getJzJfprice());
            }
            if (c.getJzDfprice()!=null){
                b+=Integer.parseInt(c.getJzDfprice());
            }
            if (c.getA()!=null){
                d+=Integer.parseInt(c.getA());
            }
            if (c.getB()!=null){
                e+=Integer.parseInt(c.getB());
            }
        }
        HashMap<Object,Object> map = new HashMap<>();
        map.put("a",a);
        map.put("b",b);
        map.put("d",d);
        map.put("e",e);
        map.put("p",new PageResult(findlog.getTotal(),findlog.getResult()));
        return map;
    }

}
